package in.muton.edushare.grading.panels.studentGrades;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.edushare.common.vo.Users;

public class StudentGradePanel extends EdusharePanel {
	private int currentMode = VIEW_BY_COURSE;
	private IModel<Users> userModel;
	WebMarkupContainer wmc1, wmc2;
	
	public StudentGradePanel(String id, IModel<Users> model,
			EduShareBasePage page) {
		super(id, model, page);
		this.userModel = model;
		
		add(wmc1 = new WebMarkupContainer("tab1"));
		wmc1.add(new Link<Void>("link") {
			@Override
			public void onClick() {
				setCurrentMode(VIEW_BY_COURSE);
			}
			private static final long serialVersionUID = 1L;
		});

		add(wmc2 = new WebMarkupContainer("tab2"));
		wmc2.add(new Link<Void>("link") {
			@Override
			public void onClick() {
				setCurrentMode(VIEW_BY_PROGRAM);
			}
			private static final long serialVersionUID = 1L;
		});
		setCurrentMode(VIEW_BY_COURSE);
		add(new StudentCourseGradePanel("tabPanel1", userModel, page){
			@Override
			public boolean isVisible(){
				return getCurrentMode() == VIEW_BY_COURSE;
			}
			private static final long serialVersionUID = 1L;
		});
		
		add(new StudentProgramGradePanel("tabPanel2", userModel, page){
			@Override
			public boolean isVisible(){
				return getCurrentMode() == VIEW_BY_PROGRAM;
			}
			private static final long serialVersionUID = -5514407297219018373L;
		});
		
	}

	public void setCurrentMode(int currentMode) {
		this.currentMode = currentMode;
		if(currentMode == VIEW_BY_COURSE){
			wmc1.add(new AttributeModifier("class", new Model<String>(
			"es-fbTabItemSelected es-softCornerTop")));
			wmc2.add(new AttributeModifier("class", new Model<String>(
				"es-fbTabItem es-softCornerTop")));
		}else{
			wmc1.add(new AttributeModifier("class", new Model<String>(
			" es-softCornerTop es-fbTabItem")));
			wmc2.add(new AttributeModifier("class", new Model<String>(
				"es-fbTabItemSelected es-softCornerTop")));			
		}
	}

	public int getCurrentMode() {
		return currentMode;
		
	}

	public static final int VIEW_BY_COURSE = 1;
	public static final int VIEW_BY_PROGRAM = 2;
	private static final long serialVersionUID = -4899162188176022694L;
}
